/*
 * INSANE - Interactive Structural Analysis Environment
 *
 * Copyright (C) 2003-2004
 * Universidade Federal de Minas Gerais
 * Escola de Engenharia
 * Departamento de Engenharia de Estruturas
 *
 * Author's email :     insane@dees.ufmg.br
 * Author's Website :   http://www.dees.ufmg.br/insane
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
 * 1307, USA.
 *
 */

/*
 * Created on 21/08/2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package br.ufmg.dees.insane.ui.rich.postp.postp_view.dialog;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;

import br.ufmg.dees.insane.commons.view.ViewState;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.DesktopPostp;

/**
 * @author  Samuel Silva Penna  TODO To change the template for this generated type comment go to  Window - Preferences - Java - Code Style - Code Templates
 */
public class MessageModelListDialog extends JFrame {
	/**
	 * Comment for <code>serialVersionUID</code>
	 */
	private static final long serialVersionUID = 1L;
	private DesktopPostp parent;
	
	private JTextArea messageField = new JTextArea();
	
	private JButton yesButton ;
	private JButton noButton;
	
	private JPanel messagePane;
	private JPanel buttonsPane;
	
	private String message = "\n\nA model with a same name already exist!"+"\n"+" Would you like to override?"; 
	
	
	/**
	 * Constructor method, calling super with the especific title.
	 *
	 * @param parent The parent of the class.
	 * @see gui.Interface
	 */
	public MessageModelListDialog(DesktopPostp parent, ViewState s) {
    	Image ico = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Insane64.gif"));
		this.setIconImage(ico);
		this.parent = parent;
		
		//Sets up the main panel
		JPanel mainPane = new JPanel();
		mainPane.setLayout(new GridLayout(2,2,2,2));          
		mainPane.setPreferredSize(new Dimension(350,200));
		mainPane.setMaximumSize(new Dimension(350,200));
		mainPane.setLayout(new BoxLayout(mainPane,BoxLayout.Y_AXIS));      
		// mainPane.setAlignmentX((float)SwingConstants.CENTER);
		
		messagePane = new JPanel();
		messagePane.setLayout(new GridLayout(1,2,2,2));          
		messagePane.setPreferredSize(new Dimension(350,150));
		messagePane.setLayout(new BoxLayout(messagePane,BoxLayout.X_AXIS));
		messagePane.add(new JLabel("         "));
		Icon icon = new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Information24.gif"));
		messagePane.add(new JLabel(icon));
		messagePane.add(new JLabel("         "));
		
		messageField = new JTextArea();
		messageField.setEditable(false);
		messageField.setBackground(mainPane.getBackground());
		messageField.setFont(new Font("Arial",Font.BOLD,12));
		
		messageField.append(message);
		
		messagePane.add(messageField);
		
		
		buttonsPane = new JPanel();
		buttonsPane.setLayout(new GridLayout(1,3,2,2));          
		buttonsPane.setPreferredSize(new Dimension(125,100));
		buttonsPane.setMaximumSize(new Dimension(125,100));
		buttonsPane.setLayout(new BoxLayout(buttonsPane,BoxLayout.LINE_AXIS));
		
		
		yesButton = new JButton("Yes");
		noButton = new JButton("No");
		
		//	buttonsPane.add(new JLabel("          "));
		buttonsPane.add(yesButton);
		buttonsPane.add(new JLabel("      "));
		buttonsPane.add(noButton);
//		buttonsPane.add(new JLabel("          "));
		
		
		yesButton.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						approvedPerform();
						close(event);
						
					}
				});
		
		noButton.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						close(event);
					}
				});
		
		mainPane.add(messagePane);
		mainPane.add(buttonsPane);
		
		this.add(mainPane);
		
		this.setSize(new Dimension(350,175));
		this.setTitle("Warning!");
		this.setAlwaysOnTop(true);
		this.setResizable(false);
		this.setLocationRelativeTo(this.parent);
		this.setVisible(true);
	}
	
//	*****************************************************************************
	
	public void close(ActionEvent event){
		this.dispose();
	}
	
	
	/**
	 * This method is executed on OK button click.
	 *
	 */
	public void approvedPerform() {
		try {
			
			this.setVisible(false);
			
		} catch (Exception err) {
			Toolkit.getDefaultToolkit().beep();
			this.setVisible(false);
		}
	}
	
//	*****************************************************************************
}//end of this class


